<route lang="json5" type="page">
{
  style: {
    navigationBarTitleText: '梦瑶诗歌',
    navigationStyle: 'default',
  },
  needLogin: 'true',
}
</route>
<template>
  <view class="container">
    <u-scroll-view scroll-y class="list-container">
      <view
        v-for="(item, index) in typeList"
        :key="index"
        class="list-item"
        :style="{ '--index': index }"
        @click="navigateToFavorite(item.type)"
      >
        <text class="type-name">{{ item.name }}</text>
      </view>
    </u-scroll-view>
  </view>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { http } from '@/utils/http'
import type { FavoriteTypeItem } from '@/api/favorite.typing'
import { useAuthHeaders } from '@/utils/token'

// 响应式数据
const typeList = ref<FavoriteTypeItem[]>([])
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL

// 生命周期钩子
onMounted(() => {
  getFavoriteTypes()
})

// 页面初次加载
onLoad(() => {
  usePageAuth()
})

// API 请求
const getFavoriteTypes = async () => {
  const res = await http.get<FavoriteTypeItem[]>(
    `${API_BASE_URL}/api/v1/favorite/type`,
    {},
    useAuthHeaders(),
  )

  if (res.code === 200) {
    typeList.value = res.data
  }
}
// 路由跳转
const navigateToFavorite = (collection: string) => {
  uni.navigateTo({ url: `/pages/poem/favorite-poems?collection=${collection}` })
}
</script>

<style scoped>
.container {
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;
  padding: 20rpx;
}

.list-container {
  height: calc(100vh - 40rpx);
}

.list-item {
  padding: 32rpx 40rpx;
  margin: 20rpx 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(246, 248, 250, 0.9) 100%);
  border-radius: 20rpx;
  display: flex;
  align-items: center;
  position: relative;
  transition: all 0.3s ease;
  box-shadow: 0 8rpx 24rpx rgba(143, 157, 184, 0.12);
}

.list-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8rpx;
  height: 60%;
  background: #5b8eff;
  border-radius: 0 8rpx 8rpx 0;
  transition: all 0.3s ease;
}

.list-item:active {
  transform: scale(0.98);
  box-shadow: 0 4rpx 12rpx rgba(143, 157, 184, 0.2);
}

.list-item:active::before {
  width: 12rpx;
  background: #3a6dd0;
}

.type-name {
  font-size: 34rpx;
  color: #2c3e50;
  font-weight: 500;
  position: relative;
  padding-left: 40rpx;
}

.type-name::before {
  content: '•';
  position: absolute;
  left: 0;
  color: #5b8eff;
  font-size: 48rpx;
  line-height: 1;
  top: -4rpx;
}

/* 自定义滚动条样式 */
::-webkit-scrollbar {
  width: 0;
  background: transparent;
}

/* 入场动画 */
@keyframes itemEntrance {
  from {
    opacity: 0;
    transform: translateY(20rpx);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.list-item {
  animation: itemEntrance 0.4s ease forwards;
  animation-delay: calc(var(--index) * 0.08s);
  opacity: 0;
}
</style>
